package org.example.shop.api;

import org.example.shop.dao.GoodsDao;
import org.example.shop.pojo.Goods;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Optional;

@RestController
@CrossOrigin
public class GoodsDetailController {
    @Resource
    private GoodsDao goodsDao;

    @RequestMapping("/goods/detail")
    public Goods detail(Long id){
        Optional<Goods> goods = goodsDao.findById(id);
        if(!goods.isPresent()){
            throw new RuntimeException("商品不存在");
        }
        return goods.get();
    }
}
